{"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport _objectWithoutProperties from \"@babel/runtime/helpers/esm/objectWithoutProperties\";\nvar _excluded = [\"name\", \"initialValues\", \"fields\", \"form\", \"preserve\", \"children\", \"component\", \"validateMessages\", \"validateTrigger\", \"onValuesChange\", \"onFieldsChange\", \"onFinish\", \"onFinishFailed\"];\nimport * as React from 'react';\nimport useForm from './useForm';\nimport FieldContext, { HOOK_MARK } from './FieldContext';\nimport FormContext from './FormContext';\nimport { isSimilar } from './utils/valueUtil';\nvar Form = function Form(_ref, ref) {\n  var name = _ref.name,\n    initialValues = _ref.initialValues,\n    fields = _ref.fields,\n    form = _ref.form,\n    preserve = _ref.preserve,\n    children = _ref.children,\n    _ref$component = _ref.component,\n    Component = _ref$component === void 0 ? 'form' : _ref$component,\n    validateMessages = _ref.validateMessages,\n    _ref$validateTrigger = _ref.validateTrigger,\n    validateTrigger = _ref$validateTrigger === void 0 ? 'onChange' : _ref$validateTrigger,\n    onValuesChange = _ref.onValuesChange,\n    _onFieldsChange = _ref.onFieldsChange,\n    _onFinish = _ref.onFinish,\n    onFinishFailed = _ref.onFinishFailed,\n    restProps = _objectWithoutProperties(_ref, _excluded);\n  var formContext = React.useContext(FormContext);\n  // We customize handle event since Context will makes all the consumer re-render:\n  // https://reactjs.org/docs/context.html#contextprovider\n  var _useForm = useForm(form),\n    _useForm2 = _slicedToArray(_useForm, 1),\n    formInstance = _useForm2[0];\n  var _formInstance$getInte = formInstance.getInternalHooks(HOOK_MARK),\n    useSubscribe = _formInstance$getInte.useSubscribe,\n    setInitialValues = _formInstance$getInte.setInitialValues,\n    setCallbacks = _formInstance$getInte.setCallbacks,\n    setValidateMessages = _formInstance$getInte.setValidateMessages,\n    setPreserve = _formInstance$getInte.setPreserve,\n    destroyForm = _formInstance$getInte.destroyForm;\n  // Pass ref with form instance\n  React.useImperativeHandle(ref, function () {\n    return formInstance;\n  });\n  // Register form into Context\n  React.useEffect(function () {\n    formContext.registerForm(name, formInstance);\n    return function () {\n      formContext.unregisterForm(name);\n    };\n  }, [formContext, formInstance, name]);\n  // Pass props to store\n  setValidateMessages(_objectSpread(_objectSpread({}, formContext.validateMessages), validateMessages));\n  setCallbacks({\n    onValuesChange: onValuesChange,\n    onFieldsChange: function onFieldsChange(changedFields) {\n      formContext.triggerFormChange(name, changedFields);\n      if (_onFieldsChange) {\n        for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n          rest[_key - 1] = arguments[_key];\n        }\n        _onFieldsChange.apply(void 0, [changedFields].concat(rest));\n      }\n    },\n    onFinish: function onFinish(values) {\n      formContext.triggerFormFinish(name, values);\n      if (_onFinish) {\n        _onFinish(values);\n      }\n    },\n    onFinishFailed: onFinishFailed\n  });\n  setPreserve(preserve);\n  // Set initial value, init store value when first mount\n  var mountRef = React.useRef(null);\n  setInitialValues(initialValues, !mountRef.current);\n  if (!mountRef.current) {\n    mountRef.current = true;\n  }\n  React.useEffect(function () {\n    return destroyForm;\n  },\n  // eslint-disable-next-line react-hooks/exhaustive-deps\n  []);\n  // Prepare children by `children` type\n  var childrenNode;\n  var childrenRenderProps = typeof children === 'function';\n  if (childrenRenderProps) {\n    var values = formInstance.getFieldsValue(true);\n    childrenNode = children(values, formInstance);\n  } else {\n    childrenNode = children;\n  }\n  // Not use subscribe when using render props\n  useSubscribe(!childrenRenderProps);\n  // Listen if fields provided. We use ref to save prev data here to avoid additional render\n  var prevFieldsRef = React.useRef();\n  React.useEffect(function () {\n    if (!isSimilar(prevFieldsRef.current || [], fields || [])) {\n      formInstance.setFields(fields || []);\n    }\n    prevFieldsRef.current = fields;\n  }, [fields, formInstance]);\n  var formContextValue = React.useMemo(function () {\n    return _objectSpread(_objectSpread({}, formInstance), {}, {\n      validateTrigger: validateTrigger\n    });\n  }, [formInstance, validateTrigger]);\n  var wrapperNode = /*#__PURE__*/React.createElement(FieldContext.Provider, {\n    value: formContextValue\n  }, childrenNode);\n  if (Component === false) {\n    return wrapperNode;\n  }\n  return /*#__PURE__*/React.createElement(Component, _extends({}, restProps, {\n    onSubmit: function onSubmit(event) {\n      event.preventDefault();\n      event.stopPropagation();\n      formInstance.submit();\n    },\n    onReset: function onReset(event) {\n      var _restProps$onReset;\n      event.preventDefault();\n      formInstance.resetFields();\n      (_restProps$onReset = restProps.onReset) === null || _restProps$onReset === void 0 ? void 0 : _restProps$onReset.call(restProps, event);\n    }\n  }), wrapperNode);\n};\nexport default Form;","map":{"version":3,"names":["_extends","_objectSpread","_slicedToArray","_objectWithoutProperties","_excluded","React","useForm","FieldContext","HOOK_MARK","FormContext","isSimilar","Form","_ref","ref","name","initialValues","fields","form","preserve","children","_ref$component","component","Component","validateMessages","_ref$validateTrigger","validateTrigger","onValuesChange","_onFieldsChange","onFieldsChange","_onFinish","onFinish","onFinishFailed","restProps","formContext","useContext","_useForm","_useForm2","formInstance","_formInstance$getInte","getInternalHooks","useSubscribe","setInitialValues","setCallbacks","setValidateMessages","setPreserve","destroyForm","useImperativeHandle","useEffect","registerForm","unregisterForm","changedFields","triggerFormChange","_len","arguments","length","rest","Array","_key","apply","concat","values","triggerFormFinish","mountRef","useRef","current","childrenNode","childrenRenderProps","getFieldsValue","prevFieldsRef","setFields","formContextValue","useMemo","wrapperNode","createElement","Provider","value","onSubmit","event","preventDefault","stopPropagation","submit","onReset","_restProps$onReset","resetFields","call"],"sources":["/data/messenger.client/node_modules/rc-field-form/es/Form.js"],"sourcesContent":["import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport _objectWithoutProperties from \"@babel/runtime/helpers/esm/objectWithoutProperties\";\nvar _excluded = [\"name\", \"initialValues\", \"fields\", \"form\", \"preserve\", \"children\", \"component\", \"validateMessages\", \"validateTrigger\", \"onValuesChange\", \"onFieldsChange\", \"onFinish\", \"onFinishFailed\"];\nimport * as React from 'react';\nimport useForm from './useForm';\nimport FieldContext, { HOOK_MARK } from './FieldContext';\nimport FormContext from './FormContext';\nimport { isSimilar } from './utils/valueUtil';\nvar Form = function Form(_ref, ref) {\n  var name = _ref.name,\n    initialValues = _ref.initialValues,\n    fields = _ref.fields,\n    form = _ref.form,\n    preserve = _ref.preserve,\n    children = _ref.children,\n    _ref$component = _ref.component,\n    Component = _ref$component === void 0 ? 'form' : _ref$component,\n    validateMessages = _ref.validateMessages,\n    _ref$validateTrigger = _ref.validateTrigger,\n    validateTrigger = _ref$validateTrigger === void 0 ? 'onChange' : _ref$validateTrigger,\n    onValuesChange = _ref.onValuesChange,\n    _onFieldsChange = _ref.onFieldsChange,\n    _onFinish = _ref.onFinish,\n    onFinishFailed = _ref.onFinishFailed,\n    restProps = _objectWithoutProperties(_ref, _excluded);\n  var formContext = React.useContext(FormContext);\n  // We customize handle event since Context will makes all the consumer re-render:\n  // https://reactjs.org/docs/context.html#contextprovider\n  var _useForm = useForm(form),\n    _useForm2 = _slicedToArray(_useForm, 1),\n    formInstance = _useForm2[0];\n  var _formInstance$getInte = formInstance.getInternalHooks(HOOK_MARK),\n    useSubscribe = _formInstance$getInte.useSubscribe,\n    setInitialValues = _formInstance$getInte.setInitialValues,\n    setCallbacks = _formInstance$getInte.setCallbacks,\n    setValidateMessages = _formInstance$getInte.setValidateMessages,\n    setPreserve = _formInstance$getInte.setPreserve,\n    destroyForm = _formInstance$getInte.destroyForm;\n  // Pass ref with form instance\n  React.useImperativeHandle(ref, function () {\n    return formInstance;\n  });\n  // Register form into Context\n  React.useEffect(function () {\n    formContext.registerForm(name, formInstance);\n    return function () {\n      formContext.unregisterForm(name);\n    };\n  }, [formContext, formInstance, name]);\n  // Pass props to store\n  setValidateMessages(_objectSpread(_objectSpread({}, formContext.validateMessages), validateMessages));\n  setCallbacks({\n    onValuesChange: onValuesChange,\n    onFieldsChange: function onFieldsChange(changedFields) {\n      formContext.triggerFormChange(name, changedFields);\n      if (_onFieldsChange) {\n        for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n          rest[_key - 1] = arguments[_key];\n        }\n        _onFieldsChange.apply(void 0, [changedFields].concat(rest));\n      }\n    },\n    onFinish: function onFinish(values) {\n      formContext.triggerFormFinish(name, values);\n      if (_onFinish) {\n        _onFinish(values);\n      }\n    },\n    onFinishFailed: onFinishFailed\n  });\n  setPreserve(preserve);\n  // Set initial value, init store value when first mount\n  var mountRef = React.useRef(null);\n  setInitialValues(initialValues, !mountRef.current);\n  if (!mountRef.current) {\n    mountRef.current = true;\n  }\n  React.useEffect(function () {\n    return destroyForm;\n  },\n  // eslint-disable-next-line react-hooks/exhaustive-deps\n  []);\n  // Prepare children by `children` type\n  var childrenNode;\n  var childrenRenderProps = typeof children === 'function';\n  if (childrenRenderProps) {\n    var values = formInstance.getFieldsValue(true);\n    childrenNode = children(values, formInstance);\n  } else {\n    childrenNode = children;\n  }\n  // Not use subscribe when using render props\n  useSubscribe(!childrenRenderProps);\n  // Listen if fields provided. We use ref to save prev data here to avoid additional render\n  var prevFieldsRef = React.useRef();\n  React.useEffect(function () {\n    if (!isSimilar(prevFieldsRef.current || [], fields || [])) {\n      formInstance.setFields(fields || []);\n    }\n    prevFieldsRef.current = fields;\n  }, [fields, formInstance]);\n  var formContextValue = React.useMemo(function () {\n    return _objectSpread(_objectSpread({}, formInstance), {}, {\n      validateTrigger: validateTrigger\n    });\n  }, [formInstance, validateTrigger]);\n  var wrapperNode = /*#__PURE__*/React.createElement(FieldContext.Provider, {\n    value: formContextValue\n  }, childrenNode);\n  if (Component === false) {\n    return wrapperNode;\n  }\n  return /*#__PURE__*/React.createElement(Component, _extends({}, restProps, {\n    onSubmit: function onSubmit(event) {\n      event.preventDefault();\n      event.stopPropagation();\n      formInstance.submit();\n    },\n    onReset: function onReset(event) {\n      var _restProps$onReset;\n      event.preventDefault();\n      formInstance.resetFields();\n      (_restProps$onReset = restProps.onReset) === null || _restProps$onReset === void 0 ? void 0 : _restProps$onReset.call(restProps, event);\n    }\n  }), wrapperNode);\n};\nexport default Form;"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,oCAAoC;AACzD,OAAOC,aAAa,MAAM,0CAA0C;AACpE,OAAOC,cAAc,MAAM,0CAA0C;AACrE,OAAOC,wBAAwB,MAAM,oDAAoD;AACzF,IAAIC,SAAS,GAAG,CAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,EAAE,gBAAgB,CAAC;AACzM,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,OAAOC,OAAO,MAAM,WAAW;AAC/B,OAAOC,YAAY,IAAIC,SAAS,QAAQ,gBAAgB;AACxD,OAAOC,WAAW,MAAM,eAAe;AACvC,SAASC,SAAS,QAAQ,mBAAmB;AAC7C,IAAIC,IAAI,GAAG,SAASA,IAAI,CAACC,IAAI,EAAEC,GAAG,EAAE;EAClC,IAAIC,IAAI,GAAGF,IAAI,CAACE,IAAI;IAClBC,aAAa,GAAGH,IAAI,CAACG,aAAa;IAClCC,MAAM,GAAGJ,IAAI,CAACI,MAAM;IACpBC,IAAI,GAAGL,IAAI,CAACK,IAAI;IAChBC,QAAQ,GAAGN,IAAI,CAACM,QAAQ;IACxBC,QAAQ,GAAGP,IAAI,CAACO,QAAQ;IACxBC,cAAc,GAAGR,IAAI,CAACS,SAAS;IAC/BC,SAAS,GAAGF,cAAc,KAAK,KAAK,CAAC,GAAG,MAAM,GAAGA,cAAc;IAC/DG,gBAAgB,GAAGX,IAAI,CAACW,gBAAgB;IACxCC,oBAAoB,GAAGZ,IAAI,CAACa,eAAe;IAC3CA,eAAe,GAAGD,oBAAoB,KAAK,KAA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